package com.vf.admin.miaodong.controller;

import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppUserDressup;
import com.vf.admin.miaodong.service.AfterUserDressupService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 购买坐骑记录
 */
@Controller
@RequestMapping("/after/userdressup")
public class AfterUserDressupController extends BaseController{
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    AfterUserDressupService appUserDressupService;


    /**
     * 购买坐骑记录列表
     * @param splitPageBean
     * @param startDate  开始时间
     * @param endDate  结束时间
     * @param nick  用户昵称
     * @param phone  用户手机号
     * @param type 类型 1坐骑  2头饰 3礼物
     * @param state 状态 1、默认  2、不默认
     * @return
     */
    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean,String startDate,String endDate,String nick,String phone,
                       Integer type,Integer state){
        try{
            Map<String,Object> map = new HashMap<>();
            map.put("startDate",startDate);
            map.put("endDate",endDate);
            map.put("nick",nick);
            map.put("phone",phone);
            map.put("type",type);
            map.put("state",state);
            List<AppUserDressup> list = appUserDressupService.list(map,splitPageBean);
            //类型
            Map<Integer,String> leixingMap = Constants.getLeixingMap();
            request.setAttribute("leixingMap",leixingMap);
            //状态（1，默认，2，不默认）
            Map<Integer,String> morenMap = Constants.getMorenStateMap();
            request.setAttribute("morenMap",morenMap);

            request.setAttribute("list",list);
            request.setAttribute("splitPage",splitPageBean);
            request.setAttribute("startDate",startDate);
            request.setAttribute("endDate",endDate);
            request.setAttribute("nick",nick);
            request.setAttribute("phone",phone);
            request.setAttribute("type",type);
            request.setAttribute("state",state);
            return this.sucess("/web/after/userdressup/list");
        }catch (Exception e){
            logger.error("查看购买坐骑记录异常",e);
            return this.error("系统繁忙");
        }
    }


    /**
     * 查询到期的坐骑和头饰
     */
    @Scheduled(fixedDelay = 20000)
    public void deleteDressup() {
        appUserDressupService.delAllGuoQi();
    }

}
